package com.nbsaas.boot.data.ext.resource;

import com.nbsaas.boot.data.api.apis.QueryPrivateTemplateApi;
import com.nbsaas.boot.data.api.domain.field.QueryPrivateTemplateField;
import com.nbsaas.boot.data.api.domain.response.QueryPrivateTemplateResponse;
import com.nbsaas.boot.data.api.domain.response.QueryTemplateResponse;
import com.nbsaas.boot.data.ext.apis.QueryPrivateTemplateExtApi;
import com.nbsaas.boot.rest.filter.Filter;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class QueryPrivateTemplateExtResource implements QueryPrivateTemplateExtApi {


    @Resource
    private QueryPrivateTemplateApi queryPrivateTemplateApi;

    @Transactional
    @Override
    public QueryTemplateResponse view(Long tenant, String model) {
        QueryTemplateResponse result;
        QueryPrivateTemplateResponse temp = queryPrivateTemplateApi.oneData(
                Filter.eq(QueryPrivateTemplateField.tenant, tenant),
                Filter.eq(QueryPrivateTemplateField.model, model)

        );
        if (temp == null) {
            return null;
        }
        result = new QueryTemplateResponse();
        result.setContent(temp.getContent());
        result.setName(temp.getName());
        result.setSqlBatchObject(temp.getSqlBatchObject());
        result.setExtData(temp.getExtData());
        result.setType(temp.getType());
        result.setResultHandle(temp.getResultHandle());
        result.setPermission(temp.getPermission());
        result.setQueryType(temp.getQueryType());
        result.setStoreProcedure(temp.getStoreProcedure());
        result.setDataScope1(temp.getDataScope1());
        result.setDataScope2(temp.getDataScope2());
        result.setDataScope3(temp.getDataScope3());
        result.setDataScope4(temp.getDataScope4());
        result.setDataScope5(temp.getDataScope5());
        result.setDataScope6(temp.getDataScope6());
        result.setDateRange(temp.getDateRange());
        result.setQueryCatalog(temp.getQueryCatalog());
        result.setHeaderStyle(temp.getHeaderStyle());
        result.setDebugMode(temp.getDebugMode());
        result.setSlowQuery(temp.getSlowQuery());
        result.setClassName(temp.getClassName());
        result.setCacheModel(temp.getCacheModel());
        result.setNote(temp.getNote());
        result.setResultHandleType(temp.getResultHandleType());
        result.setId(temp.getModel());
        return result;
    }
}
